home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14404 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.9 KB

  1. Path: volanj.dayton.saic.com!John_Volan
  2. From: John G. Volan <John_Volan@ccmail.dayton.saic.com>
  3. Newsgroups: comp.lang.ada,comp.lang.c++
  4. Subject: Re: some questions re. Ada/GNAT from a C++/GCC user
  5. Date: 29 Mar 1996 19:35:27 GMT
  6. Organization: Science Applications International Corp. (SAIC)
  7. Distribution: world
  8. Message-ID: <4jhe1v$m0g@dayuc.dayton.saic.com>
  9. References: <wnewmanDoxrCp.DKv@netcom.com> <4je9ju$174r@watnews1.watson.ibm.com> <ROGOFF.96Mar28134118@sccm.Stanford.EDU>
  10. NNTP-Posting-Host: volanj.dayton.saic.com
  11. Mime-Version: 1.0
  12. Content-Type: text/plain; charset=ISO-8859-1
  13. Content-Transfer-Encoding: 8bit
  14. X-XXMessage-ID: <AD81984CB5021A68@volanj.dayton.saic.com>
  15. X-XXDate: Fri, 29 Mar 1996 13:38:20 GMT
  16.  
  17. In article <315AC5E7.3A77@escmail.orl.mmc.com>
  18. Ted Dennison, dennison@escmail.orl.mmc.com writes:
  19.  
  20. >If you want to declare variables later in the code just 
  21. >use a declare block:
  22. >   declare
  23. >      Var1 : My_Type;
  24. >      ...
  25. >   begin
  26. >      Var1 := My_Value;
  27. >      ...
  28. >   end;
  29. >
  30. >This has the added benefit of limiting the scope of Var1 to the
  31. >begin..end  block of code.
  32.  
  33. There is another benefit, but it isn't obvious unless you take into
  34. account the concurrency aspects of Ada:
  35.  
  36. A C programmer would complain about having to introduce an extra
  37. begin/end block in order to introduce variables.  Isn't the scope
  38. of a variable well-defined in C, even without this extra baggage?
  39. It just extends from the declaration to the end of whatever block
  40. you're already in.
  41.  
  42. An Ada programmer would counter that, in Ada, some variables might be
  43. instances of _task_ types.  By definition, a task object gets created
  44. when its declaration is elaborated, but it does not get _activated_
  45. (i.e., it doesn't start executing its statements) until you hit the
  46. "begin" of the enclosing block.  This guarantees that everything in the
  47. enclosing declarative region is elaborated before any a task starts up.
  48. In fact, _all_ the tasks in a declarative region are activated by the
  49. "begin", simultaneously.  (Or virtually simultaneously. The point is,
  50. Ada does not prescribe any particular order of activation, and does not
  51. preclude truly simultaneous activation if the underlying run time
  52. environment can support it.)  In effect, if a declarative region
  53. contains tasks, then there is a synchronization point at the "begin"
  54. which the Ada programmer can rely on.
  55.  
  56. C, of course, has no concurrency abstractions built in (nor does C++,
  57. last time I checked), so, gee, I guess this isn't an issue in C. :-)
  58.  
  59. ------------------------------------------------------------------------
  60. Internet.Usenet.Put_Signature
  61. ( Name => "John G. Volan", E_Mail => "John_Volan@dayton.saic.com",
  62.   Favorite_Slogan => "Ada95: The *FIRST* International-Standard OOPL",
  63.   Humorous_Disclaimer => "These opinions are undefined by SAIC, so" &
  64.     "any use would be erroneous ... or is that a bounded error now?" );
  65. ------------------------------------------------------------------------
  66.